<template>
  <div>
    <div class="login">
      <h1>day07作业登录页面</h1>
      <div class="main">
        <p>登录:<input type="text" v-model.trim="userName" @keyup.enter="login" /></p>
        <p>密码:<input type="password" v-model.trim="password" @keyup.enter="login" /></p>
        <p><button @click="login">登录</button></p>
      </div>
    </div>
    用户1: {{ users[0].userName }}===={{ users[0].password }}
    <hr />
    用户2: {{ users[1].userName }}===={{ users[1].password }}
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      userName: "",
      password: "",
      users: [
        {
          id: 1,
          userName: "admin",
          password: "123456",
        },
        {
          id: 2,
          userName: "root",
          password: "root123",
        },
      ],
    };
  },
  created() {},
  computed: {},
  methods: {
    login() {
      if (!this.userName || !this.password) {
        return alert("用户名密码都输不全,找茬是吧!");
      }
      const arr = this.users.filter((item) => {
        return item.userName == this.userName && item.password == this.password;
      });
      console.log(arr);
      if (arr.length === 0) {
        this.password = "";
        return alert("错啦!爬爬爬!!");
      }
      this.$router.push({
        name: "home1",
        params: {
          userName: arr[0].userName,
          id: arr[0].id,
        },
      });
    },
  },
};
</script>
<style lang='less'  scoped>
.login {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 80vw;
  height: 70vw;
  box-shadow: 10px 10px 10px 10px #ccc;
  background-color: rgb(251, 255, 6);
  h1 {
    width: 100%;
    text-align: center;
    color: aquamarine;
  }
  .main {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    p {
      width: 100%;
      input {
        outline: none;
        height: 30px;
        border: 2px solid #ccc;
        animation: changeColor 2s infinite;
        background: linear-gradient(
        90deg,
        rgba(255, 64, 64, 0.3) 0%,
        rgba(255, 215, 0, 0.3) 50%,
        rgba(0, 255, 0, 0.3) 100%
      );
      }
    }
    button {
      margin-top: 20px;
      width: 30vw;
      margin-left: 6vw;
      box-shadow: 5px 5px 5px #03cdf1;
      background: linear-gradient(
        90deg,
        rgba(255, 64, 64, 1) 0%,
        rgba(255, 215, 0, 1) 50%,
        rgba(0, 255, 0, 1) 100%
      );
      border-radius: 20px;
    }
  }
  @keyframes changeColor {
    0% {
      border-color: #00e1ff;
    }
    25% {
      border-color: #59db0d;
    }
    50% {
      border-color: #ffa500;
    }
    75% {
      border-color: #eafa0a;
    }
    100% {
      border-color: #ff06d5;
    }
  }
}
</style>
